import { camelize as _camelize, kebabCase as _kebabCase, roundNumber as _roundNumber, padNumber as _padNumber, validatePhoneNumber as _validatePhoneNumber, debounce as _debounce, isPromiseLike as _isPromiseLike, } from 'fan-utils';
export const isPromiseLike = _isPromiseLike;
export const camelize = _camelize;
export const kebabCase = _kebabCase;
export const roundNumber = _roundNumber;
export const padNumber = _padNumber;
export const debounce = _debounce;
export const validatePhoneNumber = _validatePhoneNumber;
/**
 * 生成统一的组件名称前缀
 * @param name 组件名
 * @returns [组件完整名称: 大驼峰]
 */
export function createNamespace(name) {
    const prefixedName = `fan-${name}`;
    return [camelize(prefixedName, true)];
}
/**
 * 生成一个唯一id
 * @param opt { prefix?: 前缀 }
 */
export function createUniqueId(opt) {
    return ('' + (opt?.prefix || '') + Math.floor(Math.random() * 10e5).toString(36));
}
/**
 * 返回数值型的比例
 * @param {Number|String} ar 2 或 2/1 或 2:1
 */
export function resolveAspectRatio(ar) {
    if (typeof ar === 'string') {
        if (ar.includes('/') || ar.includes(':')) {
            const [a, b] = ar.replace('/', ':').split(':');
            return Number(a) / Number(b);
        }
        return Number(ar);
    }
    return ar;
}
/**
 * 是否是项目内路由
 * @param url 要跳转的链接
 * @returns
 */
export function isInnerRoute(url) {
    if (!url || url.startsWith('http') || url.startsWith('alipay'))
        return false;
    return true;
}
export const doSleep = (time = 0) => {
    return new Promise((resolve) => {
        setTimeout(() => resolve(true), time);
    });
};
/**
 * 把时间差转化成具体的倒计时时间
 * @param time 时间差
 * @param hasDays 是否显示天
 * @returns
 */
export const parseTimeData = (time, hasDays = true) => {
    const SECOND = 1000;
    const MINUTE = 60 * SECOND;
    const HOUR = 60 * MINUTE;
    const DAY = 24 * HOUR;
    time = time || 0;
    let days = '00';
    let hours = '00';
    if (hasDays) {
        days = padNumber(Math.floor(time / DAY));
        hours = padNumber(Math.floor((time % DAY) / HOUR));
    }
    else {
        hours = padNumber(Math.floor(time / HOUR));
    }
    const minutes = padNumber(Math.floor((time % HOUR) / MINUTE));
    const seconds = padNumber(Math.floor((time % MINUTE) / SECOND));
    // 只展示毫秒的首位
    const milliseconds = Math.floor(Math.floor(time % SECOND) / 100);
    return {
        days,
        hours,
        minutes,
        seconds,
        milliseconds,
    };
};
